package com.sj.tensquare.article.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.sj.tensquare.article.feign.FriendFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sj.tensquare.article.entity.ArticleEntity;
import com.sj.tensquare.article.service.ArticleService;
import com.sj.common.utils.R;
import com.sj.common.utils.PageUtils;



/**
 * 文章
 *
 * @author sj
 * @email 1071842192@qq.com
 * @date 2020-12-01 17:54:17
 */
@RefreshScope//使配置中心的值动态刷新
@RestController
@RequestMapping("article/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @Autowired
    private FriendFeignService friendFeignService;

    @Value("${article.user.name}")
    private String name;
    @Value("${article.user.age}")
    private Integer age;

    @RequestMapping("/test")
    public R getAricle(){
        ArticleEntity articleEntity = new ArticleEntity();
        articleEntity.setContent("1234");
        R userlist = friendFeignService.userlist();
        return R.ok()
                .put("article",articleEntity)
                .put("userlist",userlist);
    }
    @RequestMapping("/test01")
    public R test(){
        return R.ok()
                .put("name",name)
                .put("age",age);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("article:article:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = articleService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("article:article:info")
    public R info(@PathVariable("id") String id){
		ArticleEntity article = articleService.getById(id);

        return R.ok().put("article", article);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("article:article:save")
    public R save(@RequestBody ArticleEntity article){
		articleService.save(article);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("article:article:update")
    public R update(@RequestBody ArticleEntity article){
		articleService.updateById(article);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("article:article:delete")
    public R delete(@RequestBody String[] ids){
		articleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
